import 'package:dio/dio.dart';
import 'package:easy_video/controller/app_controller.dart';
import 'package:easy_video/utensil/helps.dart';

class AppMiddleware extends Interceptor {
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    var timestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
    options.headers["X-Version"] = AppController().version;
    options.headers["X-Platform"] = AppController().platform;
    options.headers["X-RequestTime"] = timestamp;
    // 请求路径 + 请求方式 + 平台 + 版本 + 时间戳
    options.headers["X-Encryption"] = md5(
        "${options.path}${options.method.toUpperCase()}${AppController().platform}${AppController().version}${timestamp}");
    super.onRequest(options, handler);
  }
}
